﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using AForge.Imaging;
using AForge.Imaging.Filters;
using BrainTechLLC;
using BrainTechLLC.ImageOperators;

namespace BrainTechLLC.FilterExtensions
{
    /// <summary>
    /// These extension methods are used to gather information before & after a pixellate filter is applied
    /// </summary>
    public static class HandleGatherPixellateInfoExtensions
    {
        public static void HandleGatherPixellateInfoPost(this IFilter filterToApply, bool wantPostProcessInfo, ref List<RGBAndCoordinate> postProcessInfo, ref int width, ref int height, UnmanagedImage dstImg)
        {
            if (wantPostProcessInfo && typeof(Pixellate).IsAssignableFrom(filterToApply.GetType()))
            {
                Pixellate p = filterToApply as Pixellate;
                if (wantPostProcessInfo)
                {
                    postProcessInfo = new List<RGBAndCoordinate>(p.PostProcessInfo);
                    width = dstImg.Width / p.PixelWidth;
                    height = dstImg.Height / p.PixelHeight;
                }
            }
        }

        public static void HandleGatherPixellateInfoPre(this IFilter filterToApply, bool wantPostProcessInfo)
        {
            if (wantPostProcessInfo && typeof(Pixellate).IsAssignableFrom(filterToApply.GetType()))
            {
                Pixellate p = filterToApply as Pixellate;
                p.StorePostProcessInfo = true;
            }
        }
    }
}